home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / LIB / SIMPLE_G.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  9.6 KB  |  302 lines

  1.  
  2. package sub_arctic.lib;
  3.  
  4. import sub_arctic.output.loaded_image;
  5. import sub_arctic.output.drawable;
  6. import sub_arctic.input.pressable;
  7. import sub_arctic.input.grow_draggable;
  8. import sub_arctic.input.event;
  9. import sub_arctic.input.pick_collector;
  10. import sub_arctic.constraints.std_function;
  11.  
  12. /** 
  13.  * A container class for one object that provides a grow handle.  This 
  14.  * establishes constraints on its child so that it follows the size of this
  15.  * object as it grows.
  16.  *
  17.  * @author Scott Hudson
  18.  */
  19. public class simple_grow_container extends uni_container 
  20. implements pressable, grow_draggable {
  21.  
  22.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  23.  
  24.   /** 
  25.    * Full constructor.  The boolean parameter controls whether the 
  26.    * container does bounding box feedback, or simply grows with no
  27.    * other specific feedback.
  28.    *
  29.    * @param int x the initial x position of this object.
  30.    * @param int y the initial y position of this object.
  31.    * @param int w the initial width of this object.
  32.    * @param int w the initial height of this object.
  33.    * @param loaded_image hnd_img an image for the grow handle.
  34.    */
  35.   public simple_grow_container(int x, int y, int w, int h, loaded_image hnd_img) 
  36. {
  37.       super(x,y,w,h,null);
  38.       if (hnd_img != null) set_handle(hnd_img);
  39.     }
  40.  
  41.    //had:
  42.    //* @exception general PROPAGATED
  43.  
  44.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  45.  
  46.   /** Image for the grow handle */
  47.   protected loaded_image _handle = std.line_handle();
  48.  
  49.   /** 
  50.    * Image for the grow handle.
  51.    * @return loaded_image the current image for the grow handle.
  52.    */
  53.   public loaded_image handle() {return _handle;}
  54.  
  55.   /** 
  56.    * Set the image used for the grow handle.
  57.    * @param loaded_image himg the new image for the grow handle.
  58.    */
  59.   public void set_handle(loaded_image himg) 
  60.     {
  61.       if (himg != null)
  62.     {
  63.           _handle = himg;
  64.       damage_self();
  65.     }
  66.     }
  67.  
  68.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  69.  
  70.   /** 
  71.    * Override set_child to establish and/or remove constraints.
  72.    * @param int        at_indx the index to place the child at.
  73.    * @param interactor chld    the child interactor.
  74.    */
  75.   public void set_child(int at_indx, interactor chld) 
  76. {
  77.       interactor a_child; 
  78.  
  79.       /* First remove w/h constraints placed on old child */
  80.       a_child = child(at_indx); 
  81.       if (a_child != null) 
  82.     {
  83.       if ((a_child.intrinsic_constraints() & W) == 0)
  84.         a_child.set_w_constraint(NO_CONSTRAINT);
  85.       if ((a_child.intrinsic_constraints() & H) == 0)
  86.         a_child.set_h_constraint(NO_CONSTRAINT);
  87.     }
  88.       
  89.       /* now have super class do the set */
  90.       super.set_child(at_indx, chld);
  91.  
  92.       /* Establish constraints to force new child to have our size */
  93.       if (chld != null) 
  94.     {
  95.       if ((chld.intrinsic_constraints() & W) == 0)
  96.         chld.set_w_constraint(std_function.offset(PARENT.W(), 0));
  97.       if ((chld.intrinsic_constraints() & H) == 0)
  98.         chld.set_h_constraint(std_function.offset(PARENT.H(), 0));
  99.     }
  100.     }
  101.  
  102.    //had:
  103.    //* @exception op_not_supported if we don't support children (won't happen).
  104.    //* @exception general PROPAGATED
  105.  
  106.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  107.  
  108.   /** 
  109.    * Override remove_child to drop constraints.
  110.    * @param int at_index index of child to remove.
  111.    * @return interactor the removed child.
  112.    */
  113.   public interactor remove_child(int at_indx) 
  114. {
  115.       interactor chld; 
  116.  
  117.       /* First remove w/h constraints placed on old child */
  118.       chld = child(at_indx); 
  119.       if (chld != null) 
  120.     {
  121.       if ((chld.intrinsic_constraints() & W) == 0)
  122.         chld.set_w_constraint(NO_CONSTRAINT);
  123.       if ((chld.intrinsic_constraints() & H) == 0)
  124.         chld.set_h_constraint(NO_CONSTRAINT);
  125.     }
  126.  
  127.       /* then let superclass do the job */
  128.       return super.remove_child(at_indx);
  129.     }
  130.  
  131.    //had:
  132.    //* @exception op_not_supported if we don't support children (won't happen).
  133.    //* @exception general PROPAGATED
  134.  
  135.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  136.  
  137.   /** 
  138.    * Handle mouse button press input to the object.  Here, we start dragging. 
  139.    * @param event  evt       the press event.
  140.    * @param Object user_info information associated with this object at pick 
  141.    *                         time.
  142.    * @return boolean indicating whether the input was consumed.
  143.    */
  144.   public boolean press(event evt, Object user_info)
  145.     {
  146.       manager.grow_drag_focus.set_focus_to(this, evt, new point_info(0,0));
  147.  
  148.       return true;
  149.     }
  150.  
  151.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  152.  
  153.   /** 
  154.    * Companion to press().  Here we ignore this. 
  155.    * @param event  evt       the release event.
  156.    * @param Object user_info information associated with this object at pick 
  157.    *                         time.
  158.    * @return boolean indicating whether the input was consumed (here always 
  159.    *                 false).
  160.    */
  161.   public boolean release(event evt, Object user_info)
  162.     {
  163.       return false;
  164.     }
  165.  
  166.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  167.  
  168.   /** 
  169.    * Handle the start of a drag to the object.  
  170.    * @param event  evt       the event "causing" the drag.
  171.    * @param Object user_info information associated with this object at pick 
  172.    *                         time.
  173.    * @return boolean indicating whether the input was consumed.
  174.    */
  175.   public boolean drag_start(event evt, Object user_info)
  176.     {
  177.       /* nothing to do here */
  178.       return true;
  179.     }
  180.  
  181.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  182.  
  183.   /** 
  184.    * Handle a movement during a drag.  Here we just set our size to 
  185.    * follow the size indicated by the drag.
  186.    *
  187.    * @param event  evt       the event "causing" the drag.
  188.    * @param int    cur_w     new width indicated by drag.
  189.    * @param int    cur_h     new width indicated by drag.
  190.    * @param int    st_w      initial width of this object.
  191.    * @param int    st_h      initial height of this object.
  192.    * @param Object user_info information associated with this object at pick 
  193.    *                         time.
  194.    * @return boolean indicating whether the input was consumed.
  195.    */
  196.   public boolean drag_feedback(
  197.     event evt, 
  198.     int cur_w, int cur_h,
  199.     int st_w, int st_h, 
  200.     Object user_info)
  201.     {
  202.       /* don't go smaller than 1x1 */
  203.       if (cur_w < 1) cur_w = 1;
  204.       if (cur_h < 1) cur_h = 1;
  205.  
  206.     /* set our size */
  207.       set_size(cur_w, cur_h);
  208.       return true;
  209.     }
  210.  
  211.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  212.  
  213.   /** 
  214.    * Handle input corresponding to the end of a drag.  
  215.    *
  216.    * @param event  evt       the event "causing" the drag.
  217.    * @param int    cur_w     new width indicated by drag.
  218.    * @param int    cur_h     new width indicated by drag.
  219.    * @param int    st_w      initial width of this object.
  220.    * @param int    st_h      initial height of this object.
  221.    * @param Object user_info information associated with this object at pick 
  222.    *                         time.
  223.    * @return boolean indicating whether the input was consumed.
  224.    */
  225.   public boolean drag_end(
  226.     event evt, 
  227.     int cur_w, int cur_h, 
  228.     int st_w,  int st_h, 
  229.     Object user_info)
  230.     {
  231.       /* let drag_feedback to all the work */
  232.       return drag_feedback(evt, cur_w, cur_h, st_w, st_h, user_info);
  233.  
  234.       // later we probably need a callback here
  235.     }
  236.  
  237.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  238.  
  239.   /** 
  240.    * Determine if this object is "picked" by the the given point.  In this
  241.    * case, we are only picked if they hit our grow handle at the lower right.
  242.    *
  243.    * @param int            pt_x      the x coordinate of the query point.
  244.    * @param int            pt_y      the y coordinate of the query point.
  245.    * @param pick_collector pick_list the result list we add ourselves to if we 
  246.    *                                 are picked.
  247.    */
  248.   public void pick(int pt_x, int pt_y, pick_collector pick_list) 
  249. {
  250.       /* don't pick anything unless we are enabled and its inside our bounds */
  251.       if (enabled() && visible() && picked_by(pt_x, pt_y))
  252.     {
  253.       /* pick if they hit the handle */
  254.       if (pt_x <= w() && pt_x >= w()-handle().width() &&
  255.           pt_y <= h() && pt_y >= h()-handle().height())
  256.         pick_list.report_pick(this);
  257.     }
  258.     }
  259.  
  260.    //had:
  261.    //* @exception general PROPAGATED 
  262.  
  263.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  264.  
  265.   /** 
  266.    * Draw the object's current appearance.  This draws the children, along
  267.    * with a border rectangle and drag handle at the lower right.
  268.    *
  269.    * @param drawable d the surface to draw on.
  270.    */ 
  271.   protected void draw_self_local(drawable d) 
  272. {
  273.       /* let superclass draw any children we have */
  274.       super.draw_self_local(d);
  275.  
  276.       /* draw our border and grow handle over the top */
  277.       d.drawRect(0,0,w()-1,h()-1);
  278.       d.drawImage(handle(), w()-handle().width(), h()-handle().height());
  279.     }
  280.  
  281.    //had:
  282.    //* @exception general PROPAGATED.
  283.  
  284.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  285. }
  286. /*=========================== COPYRIGHT NOTICE ===========================
  287.  
  288. This file is part of the subArctic user interface toolkit.
  289.  
  290. Copyright (c) 1996 Scott Hudson and Ian Smith
  291. All rights reserved.
  292.  
  293. The subArctic system is freely available for most uses under the terms
  294. and conditions described in 
  295.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  296. and appearing in full in the lib/interactor.java source file.
  297.  
  298. The current release and additional information about this software can be 
  299. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  300.  
  301. ========================================================================*/
  302.